﻿using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Shop.Web.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            List<Product> list = ProductService.GetProducts();
            return View(list);
        }
        /// <summary>
        /// 商品详情页
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult Detail(int Id)
        {
            string Name = User.Identity.Name;
           
            if (Name=="")
            {
                ViewBag.a = ProductService.GetProductId(Id);
                return View();
            }
            else
            {
                var NameId = CustomerService.GetCustomer(Name);
                ViewBag.b = NameId.Id;
                ViewBag.a = ProductService.GetProductId(Id);
                ViewBag.c = NameId.CustName;
                return View();
            }
            
        }
        /// <summary>
        /// 向购物添加数据
        /// </summary>
        /// <param name="shopping"></param>
        /// <returns></returns>
        public ActionResult AddShopp(Shopping shopping)
        {
            int a = ShoppingService.AddShopping(shopping);
            if (a>0)
            {
                return Json(new {Success=true,Message="添加成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "添加失败" });
            }
            
        }
        /// <summary>
        /// 向订单详情添加数据
        /// </summary>
        /// <returns></returns>
        public ActionResult AddOrderDetail(OrderDetail orderDetail)
        {
            int a = OrderDetailService.AddOrderDetails(orderDetail);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "添加成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "添加失败" });
            }
        }
        

    }
}